<?php

namespace app\home\controller;

use app\common\model\Goods;

class Product extends Common
{
    
    public $user;
    
    public function initialize()
    {
        parent::initialize();
        if (!session('uid')) {
            header('location:' . url('/login'));
        }
    }
    
    public function index(Goods $goods)
    {

        $map = [];
        $list = $goods
            ->where($map)
            ->order('sort asc,create_time desc')
            ->paginate($this->pagesize);
        // 获取分页显示
        $page = $list->render();
        $list = $list->toArray();
        foreach ($list['data'] as $k => $v) {

        }
        $this->assign('list', $list['data']);
        $this->assign('page', $page);
        return $this->fetch();
    }
    
    
    public function show(Goods $goods, $id = 0)
    {
        $info = $goods->find($id);
        if (empty($info)) {
            $this->error('商品不存在');
        }
        if (isset_full($info, 'imgs')) {
            $info['imgs'] = explode(';', $info['imgs']);
        }
        $list = $goods->limit(8)->order(rand())->select();
        $this->assign('info', $info);
        $this->assign('list', $list);
        return $this->fetch();
    }
    
}